import 'package:cms/api/single.dart';
import 'package:common/export/bloc.dart';
import 'post_details_state.dart';

class PostDetailsCubit extends Cubit<PostDetailsState> {
  final int id;
  PostDetailsCubit({required this.id}) : super(PostDetailsState().init()) {
    getPostDetails();
  }

  void getPostDetails() async {
    try {
      emit(state.copyWith(isLoading: true));
      final response = await LaraPressSingleApi().getSingle(id);
      emit(state.copyWith(postDetails: response.data));
    } finally {
      emit(state.copyWith(isLoading: false));
    }
  }
}
